
#pragma once

#include "stdafx.h"

class InputHandler
{
public:
	typedef void (*InputActionCB) ( void * pData1 );

	struct Action
	{
		Action( u32 _uKey = 0, u8 _uModifierKeys = 0, u8 _uActions = 0, InputActionCB _fnAction = NULL, void * _pData1 = NULL )
			: uKey(_uKey)
			, uModifierKeys(_uModifierKeys)
			, uActions(_uActions)
			, fnAction(_fnAction)
			, pData1(_pData1)
		{}
		u32 uKey;
		u8 uModifierKeys;
		u8 uActions;
		InputActionCB fnAction;
		void * pData1;
	};

	enum
	{
		STATE_UP=0,
		STATE_DOWN
	};
	enum
	{
		KEYMOD_CTRL			= 1<<0,
		KEYMOD_SHIFT		= 1<<1,
		KEYMOD_ALT			= 1<<2,
	};
	enum
	{
		ACTION_NONE			= 0,
		ACTION_PRESSED		= 1<<0,
		ACTION_HELD			= 1<<1,
		ACTION_RELEASED		= 1<<2,
		ACTION_DOWN			= 1<<3,
	};

public:
	InputHandler ();
	~InputHandler ();

	bool Init ( );
	void Clear ( );

	void Process ( );

	void DispatchMessages ( );

	void ForceUpdateKey ( );

	void UpdateModifierKeys ( );

	void KeyMessage ( u8 uKey, u8 uState ); 

	u32 RegisterAction ( Action const & rAction );

private:
	//LPDIRECTINPUT8 m_pDirectInput;
	//LPDIRECTINPUTDEVICE8 m_pKeyboard;

private:

	enum { KEY_COUNT=256, MAX_ACTIONS=256 };
	u8 m_aKeyStatePrev[KEY_COUNT];
	u8 m_aKeyState[KEY_COUNT];
	u8 m_aKeyAction[KEY_COUNT];
	u8 m_uModifiersHeld;

	Action m_aAction[MAX_ACTIONS];
};

